package edu.java.homework.hw10.stack;

import java.util.Scanner;

public class StackFactory {

    private static StackFactory instance = null;

    private StackFactory() {

    }

    public static StackFactory instance() {
	if (instance == null) {
	    instance = new StackFactory();
	}
	return instance;
    }

    public FixedSizeStack createFixedSizeStack() {
	int sizeStack = 0;
	Scanner input = new Scanner(System.in);
	System.out.println("Would you like to fix max size of the elements "
		+ "in the stack? The default size is 100.");
	System.out.print("Y/N ? ");
	char charAnswer = input.next().charAt(0);
	if (charAnswer == 'Y' || charAnswer == 'y') {
	    System.out.print("size= ");
	    sizeStack = input.nextInt();
	    if (sizeStack <= 0) {
		throw new IllegalArgumentException(
			"The count of elements in the stack "
				+ "should be positive number");
	    }
	} else {
	    sizeStack = FixedSizeStack.getMaxSize();
	}

	FixedSizeStack fss = new FixedSizeStack(sizeStack);

	// if (input != null) {
	// input.close();
	// }
	return fss;
    }

}
